package cn.edu.fjzzit.web.myhotel.service.impl;

import cn.edu.fjzzit.web.myhotel.dto.FreeRoomDTO;
import cn.edu.fjzzit.web.myhotel.dto.RoomOrderDTO;
import cn.edu.fjzzit.web.myhotel.dto.RoomOrderDetailDTO;
import cn.edu.fjzzit.web.myhotel.mapper.FreeRoomCalendarMapper;
import cn.edu.fjzzit.web.myhotel.mapper.RoomOrderDetailMapper;
import cn.edu.fjzzit.web.myhotel.mapper.RoomOrderMapper;
import cn.edu.fjzzit.web.myhotel.mapper.RoomPriceInfoMapper;
import cn.edu.fjzzit.web.myhotel.model.FreeRoomCalendar;
import cn.edu.fjzzit.web.myhotel.model.RoomOrder;
import cn.edu.fjzzit.web.myhotel.model.RoomOrderDetail;
import cn.edu.fjzzit.web.myhotel.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RoomServiceImpl implements RoomService{
    @Autowired
    private FreeRoomCalendarMapper freeRoomCalendarMapper;

    @Autowired
    private RoomPriceInfoMapper roomPriceInfoMapper;

    @Autowired
    private RoomOrderMapper roomOrderMapper;

    @Autowired
    private RoomOrderDetailMapper roomOrderDetailMapper;

    @Override
    public List<FreeRoomDTO> findFreeRoom(String checkInDate, String checkOutDate){
        List<FreeRoomDTO> freeRoomDTOS = new ArrayList<FreeRoomDTO>();

        List<FreeRoomCalendar>freeRoomCalendarList=freeRoomCalendarMapper
                .queryByCalendarDateBetween(checkInDate,checkOutDate);
        for(FreeRoomCalendar freeRoomCalendar:freeRoomCalendarList) {
        Long roomTYpeNum = freeRoomCalendar.getRoomTypeID();
        Integer freeCount = freeRoomCalendar.getFreeCount();

        List<FreeRoomDTO> freeRoomDTOList = roomPriceInfoMapper.queryByRoomTypeNum(roomTYpeNum);
        for (FreeRoomDTO freeRoomDTO:freeRoomDTOList) {
            freeRoomDTO.setFreeCount(freeCount);
            freeRoomDTOS.add(freeRoomDTO);

        }
    }

        return freeRoomDTOS;
        }
        @Override
    public Long bookingRoom(RoomOrderDTO roomOrderDTO) {
            RoomOrder roomOrder = new RoomOrder();
            roomOrder.setCustomerName(roomOrderDTO.getCustomerName());
            roomOrder.setCustomerPhone(roomOrderDTO.getCustomrPhone());
            roomOrder.setRoomOrderState(Byte.parseByte("0"));
            roomOrderMapper.insert(roomOrder);
            for (RoomOrderDetailDTO roomOrderDetailDTO:roomOrderDTO.getRoomOrderDetailDTOList()){
                RoomOrderDetail roomOrderDetail = new RoomOrderDetail();

            }
        return roomOrder.getRoomOrderNum();
        }
        }